
import os
import zipfile


def zip_file(zip_name, target_path) -> None:
    """遍历目录进行文件和目录压缩"""
    path_li = list()
    with zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) as fz:
        for root, dirs, files in os.walk(target_path):
            for one_dir in dirs:
                path_li.append(os.path.join(root, one_dir))
            for one_file in files:
                path_li.append(os.path.join(root, one_file))
        for path in path_li:
            print(f"zip：{path}")
            fz.write(path)
        print("文件打包完成！")
